namespace Asmex.FileViewer
{
    using Asmex.ObjViewer;
    using System;
    using System.IO;

    public class MetaDataTableHeader : Region
    {
        private byte _HeapOffsetSizes;
        private byte _MajorVersion;
        private ulong _MaskSorted;
        private ulong _MaskValid;
        private byte _MinorVersion;
        private uint _Reserved;
        private byte _RIDPlaceholder;
        private uint[] _TableLengths;

        public MetaDataTableHeader(BinaryReader reader)
        {
            base.Start = reader.BaseStream.Position;
            this._TableLengths = new uint[0x40];
            this._Reserved = reader.ReadUInt32();
            this._MajorVersion = reader.ReadByte();
            this._MinorVersion = reader.ReadByte();
            this._HeapOffsetSizes = reader.ReadByte();
            this._RIDPlaceholder = reader.ReadByte();
            this._MaskValid = reader.ReadUInt64();
            this._MaskSorted = reader.ReadUInt64();
            for (int i = 0; i < 0x40; i++)
            {
                this._TableLengths[i] = (((this._MaskValid >> i) & ((ulong) 1L)) == 0L) ? 0 : ((uint) reader.ReadInt32());
            }
            base.Length = reader.BaseStream.Position - base.Start;
        }

        public byte HeapOffsetSizes
        {
            get
            {
                return this._HeapOffsetSizes;
            }
        }

        public byte MajorVersion
        {
            get
            {
                return this._MajorVersion;
            }
        }

        [ObjViewer(Hex=true)]
        public ulong MaskSorted
        {
            get
            {
                return this._MaskSorted;
            }
        }

        [ObjViewer(Hex=true)]
        public ulong MaskValid
        {
            get
            {
                return this._MaskValid;
            }
        }

        public byte MinorVersion
        {
            get
            {
                return this._MinorVersion;
            }
        }

        public uint Reserved
        {
            get
            {
                return this._Reserved;
            }
        }

        [ObjViewer(Hex=true)]
        public byte RIDPlaceholder
        {
            get
            {
                return this._RIDPlaceholder;
            }
        }

        [ObjViewer(false)]
        public uint[] TableLengths
        {
            get
            {
                return this._TableLengths;
            }
        }
    }
}
